package ru.sgu.diploma.practic.service.impl;

import ru.sgu.diploma.practic.errors.TranslateException;
import ru.sgu.diploma.practic.service.TranslateFunction;

/**
 * User: datmakin
 * Date: 15.03.11
 * Email: atmakin.dv@gmail.com
 */
public class DetermineFunctionTranslaterImpl implements TranslateFunction {

    String[] alphabet = {"0", "1", "2", "3", "4", "5", "6", "7"};

    private Integer mod = 8;

    public String[] getAlphabet() {
        return alphabet;
    }

    public String[] translate(String[] input) throws TranslateException {
        String[] result = new String[input.length];

        for (int i = 0; i < input.length; i++) {
            Integer res = ((Integer.parseInt(input[i]) + 7) % mod);
            result[i] = res.toString();
        }

        return result;
    }

    public void generateFunctionForMod(Integer mod) {
        this.mod = mod;
        alphabet = new String[mod];
        for (int i = 0; i < mod; i++)
            alphabet[i] = ""+i;

    }
}
